#授权码 ioqmceeilnqabdfb（个人测试，请修改）9054
#DJAKDWXCDOMGVHPK (mhd976)
#xingzhaohu@tju.edu.cn
import smtplib
from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText
from email.header import Header

def SendVerifyCodeEmail(target,code):
    try:
        EmailConnect = smtplib.SMTP_SSL("smtp.126.com",465)
        EmailConnect.login('mahaodong976@126.com','DJAKDWXCDOMGVHPK')
        Email = MIMEMultipart()
        Theme = Header('验证码','UTF-8').encode()
        Email['Subject'] = Theme
        Email['from'] = 'mahaodong976@126.com'
        Email['to'] = target
        Content = MIMEText('感谢您使用环湖医院XX系统，您的验证码为{}（30分钟内有效）'.format(str(code)),"plain","UTF-8")
        Email.attach(Content)
        EmailConnect.sendmail('mahaodong976@126.com',target,Email.as_string())
        EmailConnect.quit()
    except:
        print('send emall failed')
        return False
    else:
        return True

if __name__ == '__main__':
    if SendVerifyCodeEmail('1825034906@qq.com','DCBFGS'):
        print('发送成功')
    else:
        print('发送失败')